#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
快速启动脚本 - 智慧童话世界
"""

import os
import sys
import time
import webbrowser
from threading import Timer

def open_browser():
    """延迟打开浏览器"""
    time.sleep(2)
    try:
        webbrowser.open('http://localhost:5000')
        print("🌐 浏览器已打开: http://localhost:5000")
    except Exception as e:
        print(f"❌ 无法打开浏览器: {e}")

def main():
    print("🚀 启动智慧童话世界...")
    print("=" * 50)
    
    # 设置延迟打开浏览器
    Timer(3.0, open_browser).start()
    
    try:
        # 导入并启动应用
        from enhanced_fairy_tale_app import app
        
        print("✅ 应用模块加载成功")
        print("🌟 启动Flask服务器...")
        print("📱 访问地址: http://localhost:5000")
        print("🔄 按 Ctrl+C 停止服务")
        print("=" * 50)
        
        # 启动应用
        app.run(
            host='0.0.0.0',
            port=5000,
            debug=True,
            use_reloader=False
        )
        
    except ImportError as e:
        print(f"❌ 导入错误: {e}")
        print("请确保所有依赖已安装")
    except Exception as e:
        print(f"❌ 启动失败: {e}")
    
    print("\n👋 应用已停止")

if __name__ == "__main__":
    main()